package com.hundsun.fcp.manager;

import android.content.Context;
import android.content.SharedPreferences;

import com.hundsun.fcp.FcpApplication;

public class SettingManager {
	
	public static class FcpUserSetting{
		private static final String USER_PREFERENCES = "preferences.db" ;
		private static final String SET_LOCK = "set_lock";
		private static final String SET_LOCK_ERROR_COUNT ="lock_error_count";
		
		public static boolean hasLockPattern()
		{
			return SettingManager.getUserPreferences(USER_PREFERENCES).getBoolean(SET_LOCK, false);
		}
		
		public static void setLockPattern(boolean flag)
		{
			android.content.SharedPreferences.Editor editor = SettingManager.getUserPreferences(USER_PREFERENCES).edit();
			editor.putBoolean(SET_LOCK, flag);
			editor.commit();
		}
		
		public static void setLockErrorCount(int pErrorCount){
			SharedPreferences.Editor editor = SettingManager.getUserPreferences(USER_PREFERENCES).edit();
			editor.putInt(SET_LOCK_ERROR_COUNT, pErrorCount);
			editor.commit();
		}
		
		public static int getLockErrorCount(){
			return SettingManager.getUserPreferences(USER_PREFERENCES).getInt(SET_LOCK_ERROR_COUNT, 0) ;
		}
		
		
	}
	
	public static class AppSetting{
		private static final String APPSETTING_KEY = "preferences.appsettings";
		private static final String PROMPT_CREATE_LOCKPATTERN = "prompt_create_lockpattern";
		
		public static boolean promptCreateLockPattern()
	    {
	      return SettingManager.getPreferences(APPSETTING_KEY).getBoolean(PROMPT_CREATE_LOCKPATTERN, true);
	    }
		
		public static void setPromptCreateLockPattern(boolean flag)
		 {
			SharedPreferences.Editor localEditor = SettingManager.getPreferences(APPSETTING_KEY).edit();
			localEditor.putBoolean(PROMPT_CREATE_LOCKPATTERN, flag);
			localEditor.commit();
		 }
		
	}

	public static SharedPreferences getUserPreferences(String preferenceName) {
		String clientNo = "" ;
		if (FcpUserManager.getInstance().hasLoginUser()){
			clientNo = FcpUserManager.getInstance().getUserClientNo() ;
		}
		
		return getPreferences(clientNo+"_"+preferenceName);
	}
	
	
	public static SharedPreferences getPreferences(String preferenceName)
	  {
	    return FcpApplication.getInstance().getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
	  }
}
